package org.zfes.snowier.cloud.zbss.pmp.router.service.pub;

import java.util.Map;
import java.util.Optional;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.web.controller.BaseController;
import org.zfes.snowier.auth.shiro.util.SecurityUtil;
import org.zfes.snowier.cloud.zbss.pmp.dto.PmpDocumentCreateDto;
import org.zfes.snowier.cloud.zbss.pmp.dto.PmpDocumentUpdateDto;
import org.zfes.snowier.cloud.zbss.pmp.model.PmpDocument;
import org.zfes.snowier.cloud.zbss.pmp.service.IPmpDocumentService;

@Controller("org.zfes.snowier.cloud.zbss.pmp.router.service.pub.pmpDocumentController")
@RequestMapping("/pmp/service/pub/pmpDocument")
public class PmpDocumentController extends BaseController {

	@Autowired
	private IPmpDocumentService pmpDocumentService;

	@RequestMapping(value = "/loadPmpDocumentDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody Object loadPmpDocumentDataSet(@RequestParam Map<String, Object> params) {
		DataSet dataSet = pmpDocumentService.loadPmpDocumentDataSet(params);
		return ajaxQuery("dataSet", dataSet);
	}

	@RequestMapping(value = "/createPmpDocument", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody Object createPmpDocument(PmpDocumentCreateDto createDto) {
		pmpDocumentService.createPmpDocument(SecurityUtil.getUserId().get(), createDto);
		return ajaxDoneSuccess("数据操作成功 ");
	}

	@RequestMapping(value = "/loadPmpDocument", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody Object loadPmpDocument(Long id) {
		Optional<PmpDocument> ops = pmpDocumentService.loadPmpDocumentById(id);
		return ajaxQuery("pmpDocument", ops);
	}

	@RequestMapping(value = "/updatePmpDocument", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody Object updatePmpDocument(Long id, PmpDocumentUpdateDto updateDto) {
		pmpDocumentService.updatePmpDocument(id, updateDto);
		return ajaxDoneSuccess("数据操作成功 ");
	}

	@RequestMapping(value = "/deletePmpDocument", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody Object deletePmpDocument(Long id) {
		pmpDocumentService.deletePmpDocument(id);
		return ajaxDoneSuccess("数据操作成功 ");
	}

}